<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
    <script src="js/jquery-3.5.1.min.js"></script>
    <title>分享代理</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .img {
            width: 100%;
            height: 100vh;
            background-size: 100% 100%;
            background-position: center center;
            background-image: url(image/fen.png);
            overflow: auto;
        }
    </style>
</head>

<body>
    <div class='share'>
        <div class='img'></div>
    </div>
</body>
<script>
    $(() => {
        let u = navigator.userAgent;
        // 判断ios
        let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
        // 判断android
        let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1

        function getUrldata(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            let r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]);
            return null;
        }
        // 用户id
        let uid = getUrldata('user_id')
        // 商品id
        let a_id = getUrldata('id')
        $.ajax({
            type: 'POST',
            url: 'https://api.cd1a.cn/index.php/activity/Trans/QrUrl',
            data: {
                userid_locked: uid,
                id: a_id
            },
            dataType: 'json',
            async: true,
            success: function (res) {
                console.log(res)
                //是合伙人
                if (res.code == '1') {
                    $('.img').click(function () {
                        // 判断小程序环境
                        if (isWeiXin()) {
                            if (window.__wxjs_environment === 'miniprogram') {
                                $.ajax({
                                    type: 'POST',
                                    url: 'https://api.cd1a.cn/index.php/activity/swap2/downloadImg',
                                    data: {
                                        user_id: uid,
                                        imgurl: res.data
                                    },
                                    success: function (res) {
                                        window.location.href = 'javascript:history.go(-1)'
                                        return
                                    }
                                })
                            }
                        }
                        if (isiOS) {
                            window.webkit.messageHandlers.share.postMessage({
                                url: res.data
                            })
                            return
                        }
                        if (isAndroid) {
                            //Android
                            let zu = res.data
                            window.TiantianCharge_Android.share(zu)
                            return
                        }
                    })
                } else {
                    // 其他
                    info_alert(res.msg)
                }

            }
        })
    })

    //判断微信
    function isWeiXin() {
        let ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true; // 是微信端
        } else {
            return false;
        }
    }
</script>

</html>